<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>配送中转信息记录管理添加</title>
    <link rel="stylesheet" href="../../layui-v2.6.8/layui/css/layui.css">
    <script type="text/javascript" src="../../layui-v2.6.8/layui/layui.js"></script>
</head>
<body>
<form class="layui-form">
    <div class="layui-form-item">
        <label class="layui-form-label">订单编号</label>
        <div class="layui-input-block">
            <select id="oid" name="oid" lay-verify="required" lay-filter="orders">
                <option value="">请选择</option>
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">中转地址</label>
        <div class="layui-input-block">
            <select id="faddress" name="faddress" lay-verify="required" lay-filter="filial">
                <option value="">请选择</option>
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">车牌号</label>
        <div class="layui-input-block">
            <select id="vnumber" name="vnumber" lay-verify="required" lay-filter="vehicle">
                <option value="">请选择</option>
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">司机姓名</label>
        <div class="layui-input-block">
            <select id="ename" name="ename" lay-verify="required" lay-filter="employee">
                <option value="">请选择</option>
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>
<script>
    layui.use(['form','layer'],function(){
        var form = layui.form;
        var $ = layui.$;
        var layer = layui.layer;

        //订单编号
        form.on('select(orders)',function(){
            $.ajax({
                type: 'get',
                url: 'http://localhost:8080/searchOrders',
                dataType: 'json',
                async: false,
                cache: false,
                success: function(data){
                    $.each(data.data,function (index,item){
                        $('#oid').append(new Option(item.oid))
                    });
                    layui.form.render("select");
                }
            })
        });
        //中转地址
        form.on('select(filial)',function(){
            $.ajax({
                type: 'get',
                url: 'http://localhost:8080/searchAll',
                dataType: 'json',
                async: false,
                cache: false,
                success: function(data){
                    $.each(data.data,function (index,item){
                        $('#faddress').append(new Option(item.faddress,item.fid))
                    });
                    layui.form.render("select");
                }
            })
        });
        //车牌号
        form.on('select(vehicle)',function(){
            $.ajax({
                type: 'get',
                url: 'http://localhost:8080/findIdle',
                dataType: 'json',
                async: false,
                cache: false,
                success: function(data){
                    $.each(data.data,function (index,item){
                        $('#vnumber').append(new Option(item.vnumber,item.vid))
                    });
                    layui.form.render("select");
                }
            })
        });
        //司机姓名
        form.on('select(employee)',function(){
            $.ajax({
                type: 'get',
                url: 'http://localhost:8080/searchByEpost',
                dataType: 'json',
                async: false,
                cache: false,
                success: function(data){
                    $.each(data.data,function (index,item){
                        $('#ename').append(new Option(item.ename,item.eid))
                    });
                    layui.form.render("select");
                }
            })
        });
        //提交
        form.on('submit(formDemo)', function(data){
            $.ajax({
                url:'http://localhost:8080/addTransport',
                type : 'get',
                dataType: 'json',
                data: data.field,
                success: function (data) {
                    if (data.code === 0) {
                        layer.msg("添加成功", {icon: 6});
                        setTimeout(function () {
                                location.reload();//刷新页面
                            },
                            1000
                        );
                    } else {
                        layer.msg("添加失败", {icon: 5});
                    }
                }
            });
            return false;
        });
    });
</script>
</body>
</html>